const axios = require('axios');
const qs = require('qs');
const config = require('./config');

axios.defaults.timeout = 0;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
axios.defaults.baseURL = config.apiLink;

//请求拦截器
axios.interceptors.request.use((config) => {
    if(config.method === 'post'){
        config.data = qs.stringify(config.data)
    }
    return config
},(error) => {
    return Promise.reject(error)
});

//code状态码200判断
axios.interceptors.response.use((response) => {
    return response
}, (error) => {
    return Promise.reject(error)
});

module.exports = axios;
